home *** CD-ROM | disk | FTP | other *** search
/ Isometric Game Programming with DirectX 7.0 / Isometric Game Programming.iso / source / chapter10 / isohex10_4 / dsfuncs.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-29  |  1.2 KB  |  59 lines

  1. //DSFuncs.cpp
  2.  
  3. #include "DSFuncs.h"
  4.  
  5. ////////////////////////////////////////////////////
  6. //LPDSB Functions
  7. ////////////////////////////////////////////////////
  8.  
  9. LPDIRECTSOUNDBUFFER LPDSB_LoadFromFile(LPDIRECTSOUND lpds,LPCTSTR lpszFileName)
  10. {
  11.     //declare buffer pointer
  12.     LPDIRECTSOUNDBUFFER lpdsb=NULL;
  13.  
  14.     //load wav file
  15.     CWAVLoader wav;
  16.     wav.Load(lpszFileName);
  17.  
  18.     //set up buffer description
  19.     DSBUFFERDESC dsbd;
  20.     memset(&dsbd,0,sizeof(DSBUFFERDESC));
  21.  
  22.     //size
  23.     dsbd.dwSize=sizeof(DSBUFFERDESC);
  24.  
  25.     //flags
  26.     dsbd.dwFlags=DSBCAPS_LOCSOFTWARE;
  27.  
  28.     //length and sound format
  29.     dsbd.dwBufferBytes=wav.GetLength();
  30.     dsbd.lpwfxFormat=wav.GetFormat();
  31.  
  32.     //create buffer
  33.     lpds->CreateSoundBuffer(&dsbd,&lpdsb,NULL);
  34.  
  35.     DWORD buflen,buflen2;
  36.     void* bufptr;
  37.  
  38.     //lock entire buffer
  39.     lpdsb->Lock(0,0,&bufptr,&buflen,NULL,&buflen2,DSBLOCK_ENTIREBUFFER);
  40.     
  41.     //copy from wave loader to sound buffer
  42.     memcpy(bufptr,wav.GetData(),wav.GetLength());
  43.  
  44.     //unlock the buffer
  45.     lpdsb->Unlock(bufptr,buflen,NULL,buflen2);
  46.  
  47.     //return the new buffer
  48.     return(lpdsb);
  49. }
  50.  
  51. void LPDSB_Release(LPDIRECTSOUNDBUFFER* lplpdsb)
  52. {
  53.     //safe release
  54.     if(*lplpdsb)
  55.     {
  56.         (*lplpdsb)->Release();
  57.         (*lplpdsb)=NULL;
  58.     }
  59. }